<!--
    Powered By nodePPT - This is probably the best web presentation tool so far!
    version: 0.9.8-3
    site: https://github.com/ksky521/nodePPT
-->
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>python_06_模块 - By woniuppp</title>
    <link rel="stylesheet" media="all" href="./css/nodeppt2.0.css">
    <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="./css/phone.css">
    <link rel="stylesheet" media="print" href="./css/pdf.css">
    <link rel="stylesheet" href="./js/highlight/styles/monokai_sublime.css">
    <link rel="stylesheet" href="./css/font-awesome.css">
</head>
<body>
<div class="slides">
    <slides id="container">
        <slide class="slide"><section class="slide-wrapper"><article class="flexbox vcenter">
<h1>python基础教程<em>06</em>模块</h1>
<p><small>woniuppp</small></p>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>上节回顾——函数</h2>

</hgroup><article>

<ul>
<li>上节课主要内容<ul>
<li>函数创建</li>
<li>函数的返回值</li>
<li>位置参数</li>
<li>关键字参数</li>
<li>参数怎么设置默认值</li>
<li>收集所有参数</li>
<li>作用域</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>上节回顾——</h2>

</hgroup><article>

<ul>
<li>列表推倒式</li>
<li>lambda表达式</li>
<li>sorted函数</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>上节练习</h2>

</hgroup><article>

<ul>
<li>一个list[(1,4),(5,1),(2,3)],根据每个元组中的较大值进行排序<ul>
<li>期待结果：[(2,3),(1,4),(5,1)]</li>
<li>要求：用sorted和lambda完成</li>
<li>级别1：用lambda中用max</li>
<li>级别2：lambda中不用max</li>
<li>提示：True乘以4 ==4   Fale乘以2 == 0<pre><code class="python">
print True*4
print False*4
</code></pre></li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<ul>
<li>用函数，优化log分析的功能</li>
<li><p>实现加减乘除功能的函数</p>
<ul>
<li>级别1 不支持优先级</li>
<li><p>级别2 支持优先级，但是没有括号</p>
</li>
<li><p>def operate(str):</p>
</li>
<li>operate(&#39;1+2+3-5&#39;) == 1</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>思路，拆分，然后再搞</h2>
<h3>不考虑优先级，挨个计算</h3>

</hgroup><article>

<ul>
<li>遍历字符串</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>模块是啥</h2>

</hgroup><article>

<h3> </h3>
<pre><code class="python">
# math模块的阶乘函数
import math
print math.factorial(5)
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<pre><code class="python">
    #文件1 hello.py
    def hello_world():
        print 'hello world'
</code></pre>

<pre><code class="python">
    #文件2
    import hello
    hello.hello_world()
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>调用模块方法</h2>
<pre><code class="python">
    from hello import hello_world
    hello_world()
</code></pre>
<pre><code class="python">
    from hello import *
    hello_world()
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h3>问题： 如果文件1的内容是</h3>
<pre><code class="python">
def hello_world():
    print 'hello world1'
print 'wd'
</code></pre>

<h3>文件2内容：</h3>
<pre><code class="python">
from hello import *
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>我们只想在用python xxx.py这种形式执行的时候,才执行自己的一些功能代码</h2>
<h2>修改文件内容，用<strong>name</strong>来判断</h2>
<pre><code class="python">
def hello_world():
    print 'hello world1'
if __name__ == '__main__':
    print 'wd'

</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>做点好玩的东西</h2>
<h3>flask</h3>

</hgroup><article>

<ul>
<li>flask是啥<ul>
<li>一个python写的web框架，引入flask模块，就可以搞起了</li>
<li>特点：轻量级，方便扩展</li>
<li>简单好用等等</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>第一个flask程序</h2>
<pre><code class="python">
from flask import Flask
app = Flask(__name__)

@app.route('/',methods=["GET"])
def index():
    return 'hello world'

if __name__ == '__main__':
    app.run(host='0.0.0.0')
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>flask获取url参数</h2>
<h3>request.args.get()</h3>
<pre><code class="python">
from flask import Flask,request
app = Flask(__name__)

@app.route('/',methods=['GET'])
def index():
    print request.args.get('age')
    return 'hello world'

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9002)

</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>渲染html页面</h2>
<pre><code class="python">
from flask import Flask,request,render_template
app = Flask(__name__)

@app.route('/',methods=['GET'])
def index():
     return render_template("index.html")

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9002)
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>html表单</h2>
<ul>
<li>form<ul>
<li>name</li>
<li>action</li>
<li>method</li>
</ul>
</li>
<li>input<ul>
<li>name</li>
<li>type<ul>
<li>text</li>
<li>submit</li>
</ul>
</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>表单的属性</h2>
<ul>
<li>action 要提交的url，和flask中定义的路由匹配</li>
<li>method 提交的方式，有get和post两种、】</li>
<li>input里的name属性，要标明，后端通过name拿值</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>flask 接受数据</h2>
<ul>
<li>request.args 是获取提交表单的所有数据</li>
<li>request.args本质就是一个dict，可以用.get来获取相应key的数据</li>
</ul>
<pre><code class="python">
from flask import Flask,request
app = Flask(__name__)

@app.route('/',methods=['GET'])
def index():
    print request.args.get('age')
    return 'hello world'

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=9002)
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>前端基础之jquery</h2>
<ul>
<li>美元符号是查找元素</li>
<li>井号开头是通过id找</li>
<li>小数点是class找</li>
<li>找到元素后的操作<ul>
<li>hide隐藏，可以传入一个数值，毫秒数，有动画</li>
<li>show显示</li>
<li>on 绑定事件，传入时间类型和函数<pre><code class="javascript">
$('#hideContentSecond')
$('.class')
</code></pre></li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>实现一个tab切换的效果，js代码如下</h2>
<pre><code class="javascript">
    $('#hideContentSecond').hide()
    $('#hideBtnFirst').on('click',function(){
        $('#hideContentSecond').hide()
        $('#hideContentFirst').show()
    })
    $('#hideBtnSecond').on('click',function(){
        $('#hideContentFirst').hide()
        $('#hideContentSecond').show()
    })

</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>作业</h2>
<ul>
<li>上周计算器的题，需要优先级（不需要括号）</li>
<li>在浏览器端有一个表单，可以提交用户名和年龄<ul>
<li>提交之后，保存到文件里</li>
<li>有个页面可以看到用户名和年龄的列表</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>微信公众号</h2>

</hgroup><article>

<p><img src="./logo.jpg" alt="reboot" title="reboot"></p>

</article></section></slide>
        <slide class="slide thank-you-slide segue nobackground">
            <article class="flexbox vleft auto-fadein">
                <h2>Q &amp; A</h2>
                <h3>&lt;Thank You!&gt;</h3>
            </article>
        </slide>
        <slide class="slide logoslide dark nobackground">
            <article class="flexbox vcenter">
              <h2 style="color: white;">Powered By nodePPT v0.9.8-3</h2>
            </article>
          </slide>
        <div class="slideTip" id="tip"></div>
    </slides>
</div>
<canvas id="drawBoard" class="draw-board" width="900" height="700"></canvas>
<div class="progress"><span id="progress"></span></div>
<div id="_buttons">
    <div class="_btn-box" id="_btn-box" style="display:none;">
        <button class="fa fa-arrow-circle-left" id="_btn-prev"></button>
        <button class="fa fa-arrow-circle-right" id="_btn-next"></button>
        <button class="fa fa-paint-brush" id="_btn-brush"></button>
        <button class="fa fa-compress" id="_btn-overview" data-toggle="fa fa-expand"></button>
    </div>
    <button class="fa fa-bars" id="_btn-bar"  data-toggle="fa fa-close"></button>
</div>
<script src="./js/mixjs/lib/mix.0.3.0.min.js"></script>
<script>
var base = location.protocol + '//' + location.host;

var path = location.pathname.split('/').filter(function(v){
    return !!v;
});
path.pop();
path = path.join('/');
MixJS.config({
    baseURL: [ base, path, 'js'].join('/')+'/'
});

</script>
<script src="./js/mixjs/lib/event/broadcast.js"></script>
<script src="./js/nodeppt.js"></script>
<script>
Slide.init({
    containerID: 'container',
    drawBoardID: 'drawBoard',
    slideClass: '.slide',
    buildClass: '.build',
    progressID: 'progress',
    transition: 'slide',
    width: 1100,
    dir: './',
    
    //打开下面的注释就开启postMessage方式
    //访问网址127.0.0.1:8080/ppt/demo#client
    control:{
        type: 'postMessage',
        args:{
            isControl:  false
        }
    },
    
    tipID: 'tip'
});
MixJS.loadJS('highlight/hljs-0.8.js',function(){
    hljs.tabReplace = '  ';
    hljs.initHighlightingOnLoad();
});
</script>
<script src="./js/demo.js"></script>
<link rel="stylesheet" href="./css/demo.css">
</body>
</html>
